package result

import (
	"github.com/gin-gonic/gin"
)

const (
	VALIDATEFAILED  = 400
	SUCCESS         = 200
	FAILED          = 405
	UNAUTHORIZATION = 401
	FORBIDDEN       = 403
)

type Response struct {
	Code    int         `json:"code"`
	Data    interface{} `json:"data"`
	Message string      `json:"message"`
}

func Success(data interface{}, message string, c *gin.Context) {
	Result(SUCCESS, data, message, c)
}

func SuccessWithData(data interface{}, c *gin.Context) {
	Result(SUCCESS, data, "成功", c)
}

func SuccessWithMessage(message string, c *gin.Context) {
	Result(SUCCESS, "", message, c)
}

func Failed(c *gin.Context) {
	Result(FAILED, "", "操作失败", c)
}

func FailedWithMessage(message string, c *gin.Context) {
	Result(FAILED, "", message, c)
}

func Unauthorization(c *gin.Context) {
	Result(UNAUTHORIZATION, "", "未登录或登录已过期", c)
}
func Forbidden(c *gin.Context) {
	Result(FORBIDDEN, "", "权限不足", c)
}

func Result(code int, data interface{}, message string, c *gin.Context) {
	c.JSON(SUCCESS, Response{Code: code, Data: data, Message: message})
}

func SVSResult(data string, c *gin.Context) {
	c.Data(200, "text/html;charset=GB2312", []byte(data))
}
